﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QL_BENHVIEN
{
    public partial class frmDangnhap : DevExpress.XtraEditors.XtraForm
    {
        public static string stringConn = "";
        public frmDangnhap()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
          //  SqlConnection conn = new SqlConnection(stringConn);
            timer1.Start();
            dataGridView1.Visible = false;
            var kn = new Ketnoi(stringConn);
            dataGridView1.DataSource = kn.ExcuteQuery("select MA_NV, PASS from NHAN_VIEN");
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            /*
            try
            {
                for (int i = 0; i<dataGridView1.Rows.Count-1; i++)
                {
                    if (tbnguoidung.Text == dataGridView1.Rows[i].Cells[1].Value.ToString() && tbmatkhau.Text == dataGridView1.Rows[i].Cells[2].Value.ToString())
                    {
                        frmBPtiepnhan tn = new frmBPtiepnhan();
                        this.Hide();
                        tn.ShowDialog();
                        this.Show();
                        tbnguoidung.Text = "";
                        tbmatkhau.Text = "";
                    }
                    else MessageBox.Show("dang nhap that bai, vui long kiem tra lai! ");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
             */
            var kn = new Ketnoi(frmDangnhap.stringConn);
            kn.Open();
            SqlConnection conn = new SqlConnection(frmDangnhap.stringConn);
            DataSet dSet = new DataSet();
            SqlDataAdapter sqlDAdapter = new SqlDataAdapter("SELECT MA_NV,PASS FROM NHAN_VIEN WHERE MA_NV = '" + tbnguoidung.Text.ToString() + "' and PASS = '" + tbmatkhau.Text.ToString() + "'", conn);

            sqlDAdapter.Fill(dSet);
            conn.Dispose();
            sqlDAdapter.Dispose();


            if (dSet.Tables[0].Rows.Count != 0)
            {
                MessageBox.Show("Ket noi thanh cong");
                frmBPtiepnhan tn = new frmBPtiepnhan();
                
                tn.Text = " BỘ PHẬN TIẾP NHẬN ";
                this.Hide();
                tn.ShowDialog();
            }
            else MessageBox.Show("Ket noi that bai");
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            int i = 5;
            labelControl1.Left += 1;
            while (labelControl1.Left > this.Width - labelControl1.Width || labelControl1.Left <= 0)
            {
                i = -1;
            }
        }

    }
}
